package com.example.tests;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;

import com.example.fw.ApplicationManager;

public class TestBase {

	protected ApplicationManager app;

	@BeforeTest
	public void setUp1() throws Exception {
		app = new ApplicationManager();
	}

	@AfterTest
	public void tearDown1() throws Exception {
		app.stop();
	}
	@DataProvider
	public Iterator<Object[]> rendomValidGroupGenerator() {
		List<Object[]> list = new ArrayList<Object[]>();
		for (int i = 0; i < 5; i++){
			GroupData group = new GroupData();
			group.name = generateRandomString();
			group.header = generateRandomString();
			group.footer = generateRandomString();
			list.add(new Object[]{group});
		}
		return list.iterator();
	}
		
		public String generateRandomString() {
			Random rnd = new Random();
			if (rnd.nextInt(3) == 0) {
				return  "";
			} else {
				return "test"  + rnd.nextInt();
			}
		
	}
		@DataProvider
		public Iterator<Object[]> randomValidContactGenerator() {
			List<Object[]> list = new ArrayList<Object[]>();
			for (int i = 0; i < 5; i++) {
				ContactData stringgroup = new ContactData();
				stringgroup.firstname = generateRandomString();
				stringgroup.firstname = generateRandomString();
				stringgroup.lastname = generateRandomString();
				stringgroup.address1 = generateRandomString();
				stringgroup.mobile = generateRandomString();
				stringgroup.home = generateRandomString();
				stringgroup.mobile1 = generateRandomString();
				stringgroup.work = generateRandomString();
				stringgroup.email = generateRandomString();
				stringgroup.email2 = generateRandomString();
				stringgroup.day = generateRandomString();
				stringgroup.mouth = generateRandomString();
				stringgroup.year = generateRandomString();
				stringgroup.group = generateRandomString();
				stringgroup.address2 = generateRandomString();
				stringgroup.home1 = generateRandomString();
				list.add(new Object[] { stringgroup });
			}
			return list.iterator();

		}
}
